package game.ball;

import game.ball.Free;
import game.components.MatchScene;
import game.soccerField.SoccerField;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Sprite;

public class SoccerBall extends GameComponent<MatchScene> {

	private int ratio = 21;
	private SoccerBallState state;
	
	public SoccerBall(int x, int y) {
		super(x,y);
		this.setAppearance(Sprite.fromImage("/images/ball.png").crop(2, 2, 60, 60).scale(0.75));
		this.setState(new Free(this));
	}
	
	@Override
	public void update(DeltaState deltaState) {
		super.update(deltaState);
		
		if (this.goThroughTheBand()) {
			// TODO: Crear la escena del saque lateral
		}
		
//		if (this.goThroughTheGoal())
//		
//		if (this.goThroughTheBottom())
		
		this.getState().update(deltaState);
	}
	
	private boolean goThroughTheBand() {
		return this.getY() < SoccerField.UPPER_LATERAL_BAND || this.getY() > SoccerField.LOWER_LATERAL_BAND;
	}

	public void moveNormally(double x, double y) {
		SoccerField field = this.getScene().getField();	
		this.getState().move(field, x, y);
	}
	
	public void roll(int speed, double i, double j) {
		this.setState(new Free(this, speed, i, j));		
	}
	
	public boolean isWithinField() {
		return this.getState().isWithinTheField(this.getScene().getField());
	}
	
	public boolean isFree(){
		return this.state.isFree();
	}
	
	
	

	public int getRatio() {
		return ratio;
	}

	public SoccerBallState getState() {
		return state;
	}

	public void setState(SoccerBallState state) {
		this.state = state;
	}
}
